package geektime.spring.springbucks.controller;

import geektime.spring.springbucks.model.Coffee;
import geektime.spring.springbucks.service.CoffeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class CoffeeController {
    @Autowired
    private CoffeeService coffeeService;

    @RequestMapping(value = "/getCoffeeJson",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public List<Coffee> findById(){
        List<Coffee> all = coffeeService.findAll();
        return all;
    }

    @RequestMapping(value = "/getByNameXml/{name}",method = RequestMethod.GET,produces = MediaType.APPLICATION_XML_VALUE)
    @ResponseBody
    public Coffee findByName(@PathVariable String name){
        Coffee byName = coffeeService.findByName(name);
        System.out.println(byName);
        return byName;
    }
}
